#include <iostream>
#include <string>
#include <cmath>
#include <map>
#include <stdlib.h>
using namespace std;

const char* source = 
	" major = 1			"
	" minor = 0			"
	" type  = 'stable 1';u=' abcd    s'; "
	" patch = 8			;";

enum Type{
	key,
	number,
	_string,
	_equal,
	other,
	semicolon,
};
struct type_value{
	Type type;
};
map<char*, int> map_number;
map<char*, char*> map_string;
type_value type_1[100];
int sl = 0;
void get_type_value ( const char*, int &, type_value []);
int check_source ( const char*);
void get_value(const char*);
void get_string(const char*, char [], int &);
void get_key(const char*,char [], int &);
int main(){
	if ( check_source( source) == 0) cout << "source incorrect";
	get_value(source);
	cout << map_number ["patch"];
	system("pause");
	return 0;
}
void get_type_value ( const char* source, int &sl, type_value t_1[]){
	int i = 0;
	while ( i < strlen ( source) - 1){
		int t = 0;
		while ( source[i] == ' ' || source[i] == '\t' || source[i] == '\n')i++;
		if (source[i] == '\0') break; 
		/////////////////////////////////////////////////
		if ( source[i] >= 'a' && source[i] <= 'z'
			|| source[i] >= 'A' && source[i] <= 'Z') t_1[sl].type = key;
		else if (source[i] >= '0' && source[i] <= '9') t_1[sl].type = number;
		else if ( source[i] == '=') t_1[sl].type = _equal;
		else if ( source[i] == '\'') t_1[sl].type =  _string;
		else if ( source[i] == ';') t_1[sl].type = semicolon;
		else t_1[sl].type = other;
		///////////////////////////////////////////
		if ( t_1[sl].type == _string){
			t++;
			while ( source[i + t] != '\'') t++;
			sl++;
			t++;
		}
		else if (t_1[sl].type == number){
			while ( source[i + t] != ' ' && source [i + t] != ';' && source[i + t] != '\t' && source[i + t] != '\n' && source[i + t] != '=' ){
				if ( source[i + t] > '9' || source[i + t] < '0'){
					t_1[sl].type = other;
					t++;
					break;
				}
				t++;
			}
			sl++;
		}
		else{
			sl ++;
			if ( source[i] == '=') i++;
			else if ( source[i] == ';') i++;
			else{
				while ( source[i + t] != ' ' && source [i + t] != ';' && source[i + t] != '\t' && source[i + t] != '\n' && source[i + t] != '=') t++;
			}
		}
		i = i + t;
	}
}
int check_source ( const char*){
	get_type_value ( source, sl, type_1);
	for ( int i = 0; i < sl - 2; i++){
		while (type_1[i].type != key){
			i++;
			if ( i > sl - 1) return 1;
		}
		if ( !(type_1[i].type == key && type_1[i + 1].type == _equal && ( type_1[i + 2].type == number || type_1[i + 2].type == _string))) return 0;
	}
	return 1;
}
void get_string(const char * source, char str[], int &t){
	int j = 0;
	while ( source[t] != '\''){
		str[j] = source[t];
		j++;
		t++;
	}
	str[j + 1] = '\0';
}
void get_key( const char* source,char str[], int &t){
	int j = 0;
	while (true){
		str[j] = source[t];
		j++;
		t++;
		if ( source[t] == ' ' || source[t] == ';' || source[t] == '=' || source[t] == '\t' || source[t] == '\n') break;
	}
	str[j] = '\0';
}
void get_value(const char* source){
	int t = 0;
	int i = 0;
	char str_1[100], str_2[100];
	while (t < strlen(source)){
		if ((source[t] >= 'a' && source[t] <= 'z') 
			|| ( source[t] >= 'A' && source[t] <= 'Z') 
			|| (source[t] >= '0' && source[t] <= '9')
			|| source[t] == '\''){
				if (type_1[i].type == key){
					get_key(source, str_1, t);
					i = i + 2;
					if (type_1[i].type == number){
						get_key(source, str_2, t);
						map_number[str_1] = atoi(str_2);
					}
					if (type_1[i].type == _string){
						get_string(source, str_2, t);
						map_string[str_1] = str_2;
					}

				}
		}
		i++;
	}
}

